package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Customer;
import cn.wolfcode.rbac.mapper.EmployeeMapper;
import cn.wolfcode.rbac.query.CustomerQuery;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.ICustomerService;
import cn.wolfcode.rbac.service.ISystemDictionaryItemService;
import cn.wolfcode.rbac.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private ICustomerService service;
    @Autowired
    private ISystemDictionaryItemService sdiService;
    @Autowired
    private EmployeeMapper emapper;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")CustomerQuery qo, Model model){
        model.addAttribute("seller",this.emapper.findSeller());
        model.addAttribute("result",this.service.query(qo));
        return "customer/list";
    }

    //潜在客户列表
    @RequestMapping("/potentialList")
    public String potentialList(@ModelAttribute("qo")CustomerQuery qo, Model model){
        model.addAttribute("seller",this.emapper.findSeller());
        model.addAttribute("result",this.service.query(qo));
        model.addAttribute("jobs",this.sdiService.findFromSDI(1));
        model.addAttribute("sources",this.sdiService.findFromSDI(2));
        model.addAttribute("ccts",this.sdiService.findFromSDI(26));
        model.addAttribute("sellers",this.emapper.findSeller());
        return "customer/potential_list";
    }

    //客户池列表
    @RequestMapping("/poolList")
    public String poolList(@ModelAttribute("qo") CustomerQuery qo, Model model){
        model.addAttribute("result",this.service.query(qo));
        model.addAttribute("sellers",this.emapper.findSeller());
        return "/customer/pool_list";
    }
    //失败客户列表
    @RequestMapping("/failList")
    public String failListList(@ModelAttribute("qo") CustomerQuery qo, Model model){
        model.addAttribute("result",this.service.query(qo));
        model.addAttribute("sellers",this.emapper.findSeller());
        return "/customer/fail_list";
    }
    //正式客户列表
    @RequestMapping("/officialList")
    public String officialList(@ModelAttribute("qo")CustomerQuery qo,Model model){
        model.addAttribute("result",this.service.query(qo));
        model.addAttribute("sellers",this.emapper.findSeller());
        return "/customer/official_list";
    }
    //流失客户列表
    @RequestMapping("/turnoverList")
    public String turnoverList(@ModelAttribute("qo")CustomerQuery qo,Model model){
        model.addAttribute("result",this.service.query(qo));
        model.addAttribute("sellers",this.emapper.findSeller());
        return "/customer/turnover_list";
    }

    //添加或修改客户信息
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Customer customer){
        this.service.saveOrUpdate(customer);
        return new JsonResult();
    }

    //修改客户状态
    @RequestMapping("/updateStatus")
    @ResponseBody
    public JsonResult updateStatus(Customer customer){
        this.service.updateStatus(customer);
        return new JsonResult();
    }
}
